class Rudoku::Rule # IMMUTABLE objects!
  @@rules = {}
  def self.[](id)
    @@rules[id]
  end
  
  attr_reader :id, :name, :desc, :reason, :logic
  
  def initialize(params, &logic)
    # add all rules to the rules hash
    @id, @name, @desc, @reason = params[:id], params[:name], params[:desc], params[:reason]
    @name ||= @id.to_s.gsub("_", " ")
    @logic = logic
    @@rules[@id] = self if @id
  end
  
  def apply_to(sudoku)
    eliminations = []
    catch(:abort) { eliminations = run(sudoku) }    
    eliminations
  end
  
  def run(sudoku)
    RuleLogicDslProxy.new(self, sudoku).run.eliminations
  end
end
